package com.crl.rcdp.monitor.controller;

import com.cars.util.bean.BasePage;
import com.cars.util.json.JsonResult;
import com.cars.util.json.JsonResultUtil;
import com.crl.rcdp.monitor.service.MonitorOnlineService;
import com.crl.rcdp.sys.dto.SysUserDTO;
import com.crl.rcdp.sys.vo.SysUserSearchVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @description:
 * @author: 孔垂云
 * @version: 1.0
 * @date: 2020/7/8 13:56
 */
@RestController
@RequestMapping("/monitor/online")
@Api(description = "在线用户", tags = "01.在线用户")
public class MonitorOnlineController {
    @Autowired
    private MonitorOnlineService monitorOnlineService;

    /**
     * 查询日志
     */
    @PostMapping("/list")
    @ApiOperation(value = "查询列表", notes = "查询在线用户", response = JsonResult.class)
    public JsonResult list(@RequestBody SysUserSearchVO sysUserSearchVO) {
        BasePage<List<SysUserDTO>> basePage = new BasePage();
        int count = monitorOnlineService.listOnlineCount(sysUserSearchVO);
        basePage.setTotal(count);
        List<SysUserDTO> list = monitorOnlineService.listOnline(sysUserSearchVO);
        basePage.setData(list);
        return JsonResultUtil.ok(basePage);
    }

    /**
     * 强制下线
     * @param sysUserSearchVO
     * @return
     */
    @PostMapping("/logout")
    @ApiOperation(value = "强制下线", notes = "强制下线", response = JsonResult.class)
    public JsonResult logout(@RequestBody SysUserSearchVO sysUserSearchVO) {
        monitorOnlineService.logout(sysUserSearchVO);
        return JsonResultUtil.ok();
    }


}
